/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author zhang
 */
public class DatabaseUtil {
    public static Connection connect(){
        Connection con=null;
        try{
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=bookstore","sa","sa");
        }catch(Exception e){
            e.printStackTrace();
        }
        return con;
    }
    
    public static void closeConnection(Connection con,Statement stmt,ResultSet rs){
        try{
            if(rs!=null)  rs.close();
            if(stmt!=null)  stmt.close();
            if(con!=null)  con.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
